import * as dataDic from '../js/data'
import { getDicByKey } from '@/libs/getDicDataList'
import { queryCustom } from '@/api/customer' // 海关编码查询

/**
 * 报关单页面所有下拉数据字典
 */
export default {
    data () {
        return {
            billTypeList: Object.freeze(dataDic.billTypeList), //  清单类型
            booleanList: Object.freeze(dataDic.booleanList), // 是否
            feeMarkList: Object.freeze(dataDic.feeMarkList), // 运费
            insurMarkList: Object.freeze(dataDic.insurMarkList), // 保险费杂费
            entryTypeList: Object.freeze(dataDic.entryTypeList), //  报关单类型
            useCodeList: Object.freeze(dataDic.useCodeList), //  用途数据字典

            currencyCodeList: [], // 币制数据字典
            wrapTypeList: [], // 包装种类
            customsCodeList: [], // 海关数据字典
            trafModeList: [], // 运输方式数据字典
            tradeModeList: [], // 监管方式数据字典
            cutModeList: [], // 征免性质数据字典
            countryRegionList: [], // 国家数据字典
            originAreaList: [], // 原产地区数据字典
            districtCodeList: [], // 境内目的地数据字典
            destCodeList: [], // 目的地代码数据字典
            dutyModeList: [], // 征免方式数据字典
            distinatePortList: [], // 经停港 & 启运港
            transModeList: [], // 成交方式
            entyPortCodeList: [], // 入境口岸
            orgCodeList: [], // 机关数据字典
            unitList: [], // 单位数据字典

            containerTypeList: [], // 装箱规格
            supervisionList: [], // 随附单证代码

            custIdList: [] //  委托单位数据字典
        }
    },
    methods: {
        // 获取数据字典
        queryDicList () {
            this.getBZList()
            this.getCustomsCodeList()
            this.getTrafModeList()
            this.getTradeModeList()
            this.getCutModeList()
            this.getCountryRegionList()
            this.getOriginAreaList()
            this.getDistrictCodeList()
            this.getDestCodeList()
            this.getDutyModeList()
            this.getContainerTypeList()
            this.getSupervisionList()
            this.getDistinatePortList()
            this.getTransModeList()
            this.getEntyPortCodeList()
            this.getOrgCodeList()
            this.getUnitList()
            this.getPAackageType()
            this.getCustIdList('')
        },
        // 获取币制关别
        getBZList () {
            return getDicByKey('CURRENCY_CODE').then(list => {
                this.currencyCodeList = Object.freeze(list)
            })
        },
        // 获取包装种类
        getPAackageType () {
            return getDicByKey('PACKAGE_TYPE').then(list => {
                this.wrapTypeList = Object.freeze(list)
            })
        },
        // 获关别
        getCustomsCodeList () {
            return getDicByKey('CUSTOMS_CODE').then(list => {
                this.customsCodeList = Object.freeze(list)
            })
        },
        getTrafModeList () {
            return getDicByKey('TRAF_MODE').then(list => {
                this.trafModeList = Object.freeze(list)
            })
        },
        getTradeModeList () {
            return getDicByKey('TRADE_MODE').then(list => {
                this.tradeModeList = Object.freeze(list)
            })
        },
        getCutModeList () {
            return getDicByKey('CUT_MODE').then(list => {
                this.cutModeList = Object.freeze(list)
            })
        },
        getCountryRegionList () {
            return getDicByKey('COUNTRY_REGION').then(list => {
                this.countryRegionList = Object.freeze(list)
            })
        },
        getOriginAreaList () {
            return getDicByKey('ORIGIN_AREA').then(list => {
                this.originAreaList = Object.freeze(list)
            })
        },
        getDistrictCodeList () {
            return getDicByKey('INLAND_REGION').then(list => {
                this.districtCodeList = Object.freeze(list)
            })
        },
        getDestCodeList () {
            return getDicByKey('DEST_CODE').then(list => {
                this.destCodeList = Object.freeze(list)
            })
        },
        getDutyModeList () {
            return getDicByKey('DUTY_MODE').then(list => {
                this.dutyModeList = Object.freeze(list)
            })
        },
        getContainerTypeList () {
            return getDicByKey('CONTAINER_TYPE').then(list => {
                this.containerTypeList = Object.freeze(list)
            })
        },
        getSupervisionList () {
            return getDicByKey('SUPERVISION').then(list => {
                this.supervisionList = Object.freeze(list)
            })
        },
        getDistinatePortList () {
            return getDicByKey('PORT').then(list => {
                this.distinatePortList = Object.freeze(list)
            })
        },
        getTransModeList () {
            return getDicByKey('TRANS_MODE').then(list => {
                this.transModeList = Object.freeze(list)
            })
        },
        getEntyPortCodeList () {
            return getDicByKey('INSIDE_PORT').then(list => {
                this.entyPortCodeList = Object.freeze(list)
            })
        },
        getOrgCodeList () {
            return getDicByKey('IAQO_CODE').then(list => {
                this.orgCodeList = Object.freeze(list)
            })
        },
        getUnitList () {
            return getDicByKey('UNIT').then(list => {
                this.unitList = Object.freeze(list)
            })
        },
        // 获得委托单位
        getCustIdList (query) {
            let data = {
                key: query,
                pageNum: 1,
                pageSize: 10000
            }
            return queryCustom(data).then(res => {
                if (res.data.code === '0000') {
                    this.custIdList = Object.freeze(res.data.data.list)
                } else {
                    this.custIdList = []
                }
                return res
            })
        }
    }
}
